﻿namespace MyCompany.Core {
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Linq;
	using System.Text.RegularExpressions;

	/// <summary>
	///     Validators or other utilities. For converters, use the Conversions class instead.
	/// </summary>
	public static class Utilities {
		/// <summary>
		///     Check whether a path contains any invalid characters.
		///     This snippet is based on
		///     http://stackoverflow.com/questions/62771/how-check-if-given-string-is-legal-allowed-file-name-under-windows#62855.
		/// </summary>
		public static bool IsPathValidCharacters(string pathToCheck) {
			return !(new Regex("[" + Regex.Escape(new string(Path.GetInvalidPathChars())) + "]")).IsMatch(pathToCheck);
		}

		public static string GetFullHttpAddressWithPort(string localIPAddressWithoutHttpPrefix, int port) {
			return "http://" + localIPAddressWithoutHttpPrefix + ":" + port + "/";
		}

		public static string GetFullWebSocketAddressWithPort(string localIPAddressWithoutHttpPrefix, int port) {
			return "ws://" + localIPAddressWithoutHttpPrefix + ":" + port;
		}
	}

	/// <summary>
	///     Usage: var values = EnumUtil.GetValues<Foos>();
	/// </summary>
	public static class EnumUtil {
		public static IEnumerable<T> GetValues<T>() {
			return Enum.GetValues(typeof(T)).Cast<T>();
		}
	}
}
